package net.whzjkj.gateway.tcpserver.processor.command;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import net.whzjkj.gateway.core.codce.JT808MessageDecoder;
import net.whzjkj.gateway.model.vo.PackageData;
import net.whzjkj.gateway.model.vo.ObdLocationVO;
import net.whzjkj.gateway.model.vo.QueueMessageVO;
import net.whzjkj.gateway.tcpserver.constant.JT808Constant;
import net.whzjkj.gateway.tcpserver.processor.AbstractMessageProcessor;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @description: 位置信息汇报
 * @author: Mr.Hu
 * @create: 2018-11-02 16:55
 **/
@Component
public class CMD0200 extends AbstractMessageProcessor {

    @Resource
    private JT808MessageDecoder messageDecoder;
    /**
     * 处理终端消息
     * @param pkgData
     * @throws Exception
     */
    @Override
    public void processTerminalMessage(PackageData pkgData) throws Exception {
        //调用平台统一应答消息
        super.serverCommonRespond(pkgData);
        ObdLocationVO obdLocation = decoderPackageData(pkgData);
        QueueMessageVO<ObdLocationVO> queueMessage = new QueueMessageVO<>(obdLocation);
        queueMessage.setMessageId(pkgData.getMessageHeader().getMessageId());
        super.send2Queue(JSONObject.toJSONString(queueMessage));
    }

    private ObdLocationVO decoderPackageData(PackageData pkgData){
        ObdLocationVO obdLocation = new ObdLocationVO(pkgData);
        final byte[] data = obdLocation.getMessageBodyBytes();


        return obdLocation;
    }


    /**
     * 验证消息是否支持
     * @param data
     * @return
     */
    @Override
    public boolean support(PackageData data) {
        return data.getMessageHeader().getMessageId()== JT808Constant.CMD_TERMINAL_0200;
    }
}
